<?php

$table_source = $old_nav_db_config['DB_PREFIX'].'group_city';

$table_target = $db_config['DB_PREFIX'].'group_city';



$db_target->query("TRUNCATE $table_target");

$data_list = $db_source->query("SELECT * FROM $table_source");

showjsmessage("开始转换数据表　group_city",2);

$data_count = count($data_list);

$start_sql = "INSERT INTO $table_target (`id`, `name`, `sort`, `status`, `py`, `is_fix`, `is_default`, `is_hot`, `py_t`, `img`) VALUES ";



$is_china = false;



for($j=0; $j< $data_count; $j++)

{

	$data = $data_list[$j];

	unset($data['py_t']);

	if($data['name'] == '全国')

	{

		$data['py'] = 'china';

		$data['status'] = '1';

		$is_china = true;

		$data['is_fix'] = 1;

	}

	else

		$data['is_fix'] = 0;

	

	if(!isset($data['is_default']))

		$data['is_default'] = 0;

	

	if(!isset($data['is_hot']))

		$data['is_hot'] = 0;

		

	$data['py_t'] = strtoupper(substr($data['py'],0,1));

		

	if(!isset($data['img']))

		$data['img'] = '';

	else

		$data['img'] = preg_replace("/^\/Public/", '/public', $data['img']);

	

	$record = array_map('dumpEscapeString', $data);//过滤非法字符

	$sql = $start_sql . ' ('. implodeInsertValues($record) .')';

	$db_target->query($sql);

}



if(!$is_china)

{

	$db_target->query($start_sql."(NULL,'全国',1,1,'china',1,0,0,'c','')");

}



showjsmessage("转换数据表　group_city ... 成功");

showjsmessage(U('Index/convert',array('table'=>'area','begin'=>0)),5);
?>